using DTFramework.Entity;
using UnityEngine;
namespace DTFramework.UI
{
    public class PoiFormBase : UGuiForm
    {
        [SerializeField] protected RectTransform m_rootBG;
        [SerializeField] protected Vector2 Add_OffsetXY = new Vector2(40f, 90f);
        [SerializeField] protected bool IsAdjustPoint = true;
        protected Canvas _rootCanvas;
        
        protected override void OnInit(object userData)
        {
            base.OnInit(userData);
            _rootCanvas = this.GetComponent<Canvas>();
        }
        protected override void OnOpen(object userData)
        {
            base.OnOpen(userData);
        }
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);
        }

        protected override void OnClose(bool isShutdown, object userData)
        {
            base.OnClose(isShutdown, userData);
        }

        protected void SetPosition(Vector3 pos)
        {
            if (!IsAdjustPoint) return; ;
            if (_rootCanvas.WorldToUGUIPoint(pos, out Vector2 localPoint))
            {
                m_rootBG.localPosition = localPoint + Add_OffsetXY;
            }
        }
    }
}